package com.jh.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jh.dto.OderPageQueryDTO;
import com.jh.vo.TopSalesVO;
import com.jh.entity.Order;
import com.jh.vo.OderPageQueryVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;
import java.time.LocalDateTime;

@Mapper
public interface OrderMapper extends BaseMapper<Order> {


    /**
     * 根据订单号查询订单id
     * @param orderCode
     * @return
     */
    @Select("SELECT id FROM `order` WHERE order_code = #{orderCode}")
    Long getOrderIdByOrderCode(String orderCode);

    /**
     * 订单分页查询
     *
     * @param oderPageQueryDTO
     * @return
     */
    Page<OderPageQueryVO> page(Page<OderPageQueryVO> page,@Param("oderPageQueryDTO") OderPageQueryDTO oderPageQueryDTO);

    @Delete("delete from `order` where id = #{orderId}")
    void deleteByid(Long orderId);

    @Select("SELECT COUNT(*) AS order_count " +  // 注意：在 order_count 后添加空格
            "FROM `order` " +
            "WHERE DATE(create_time) = CURDATE()")
    int getSequence();

    List<Map<String, Object>> getSalesTrend(
            @Param("startDate") LocalDateTime startDate,
            @Param("endDate") LocalDateTime endDate);

    List<TopSalesVO> getTopSales();
}

